﻿using BusinessRepository;
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Threading.Tasks;
using BusinessRule.Organization;
using BusinessEntity;
using BusinessEntity.xmglQuerryEntity;
using learun.util;
namespace BusinessRule
{
   public class FunSetRule
    {
        public static async Task<bool> InsertFunSet(List<BDicInfoFun> dicfuns,string gsid)
        {
            return await TranstionRule.GetRunActionTransAsync(async irp =>
            {
                string strsql = "delete from BDicInfoFun where dwid = '"+ gsid + "'";
                await irp.ExecuteSql(strsql);

                for (int i = 0; i < dicfuns.Count; i++)
                {
                    await irp.Insert(dicfuns[i]);
                }
 

                return true;

            });
        }

        public static async Task<IEnumerable<dynamic>> GetFunSetByGsid(string gsid)
        {
            string strsql = "select * from BDicInfoFun where dwid = '" + gsid + "'";
            return await new RepositoryFactory().BaseRepository().FindList(strsql);
        }

        public static async Task<bool> GetFunSet(string gsid, string mkid)
        {
            string strsql = "select * from BDicInfoFun where dwid = '" + gsid + "' and funid = '"+ mkid + "'";

            var dics = await new RepositoryFactory().BaseRepository().FindTable(strsql);//FindList<BDicInfoFun>
            bool run = true;
            for (int i = 0; i < dics.Rows.Count; i++)
            {
                run = dics.Rows[i]["nouse"].ToString() == "0";
            }

            return run;
        }
    }
}
